#include <graphics.h>
#include <conio.h>


int main()
{
	initgraph(640, 480);
	int ball_x[15];
	int ball_y[15];
	int ball_vx[15], ball_vy[15];
	int radius = 20;
	int i;
	int j;
	BeginBatchDraw();
	for (i = 0;i < 15;i++)
	{
		ball_x[i] = rand() % 600 + 20;
		ball_y[i] = rand() % 440 + 20;
		ball_vx[i] =1;
		ball_vy[i] =1;
	}
while (1)
{
	setcolor(YELLOW);
	setfillcolor(GREEN);
	for (i = 0; i < 15; i++)
	{
		fillcircle(ball_x[i], ball_y[i], radius);
	}
	FlushBatchDraw();
	Sleep(3);
	setcolor(BLACK);
	setfillcolor(BLACK);
	for (i = 0; i < 15; i++)
	{
		fillcircle(ball_x[i], ball_y[i], radius);
	}
	for (i = 0; i < 15; i++)
	{
		ball_x[i] = ball_x[i] + ball_vx[i];
		ball_y[i] = ball_y[i] + ball_vy[i];
		if (ball_x[i] == 620 || ball_x[i] == 20)
			ball_vx[i] = -ball_vx[i];
		if (ball_y[i] == 460 || ball_y[i] == 20)
			ball_vy[i] = -ball_vy[i];
		for (j = 0; j < 15; j++)
		{
			if (j != i)
			{
				if (((ball_x[i] - ball_x[j])*(ball_x[i] - ball_x[j]) + (ball_y[i] - ball_y[j])*(ball_y[i] - ball_y[j])) < 1600)
				{
					ball_vx[i] = -ball_vx[i];
					ball_vy[i] = -ball_vy[i];
					ball_vx[j] = -ball_vx[j];
					ball_vy[j] = -ball_vy[j];
				}
			}
		}
	}
}
	EndBatchDraw();
	closegraph();
}